<?php

namespace app\admin\controller;

class Operating extends Common {
        /*
         * @统计代码
         */

        public function statistics() {
                if (IS_POST) {
                        $sta = I("post.");
                        foreach ($sta as $key => $val) {
                                D("Travelv")->setStatis($key, $val);
                        }
                        $this->delSuccess("操作成功！");
                } else {
                        $model = M("Travelv");
                        $where = array('name' => 'statis');
                        $statis = $model->where($where)->getField("value");
                        $this->assign('statis', $statis);
                        return $this->fetch();
                }
        }

        public function tenqq() {
                if (IS_POST) {
                        if (!empty($_POST['ten'])) {
                                $tenqq = $_POST['ten'];
                                $ten = array();
                                if (!empty($tenqq)) {
                                        foreach ($tenqq as $value) {
                                                if (!empty($value['qq'])) {
                                                        $value["qq"] = htmlspecialchars($value["qq"]);
                                                }
                                                if (!empty($value['name'])) {
                                                        $value['name'] = htmlspecialchars($value['name']);
                                                }
                                                $ten[] = $value;
                                        }
                                } else {
                                        $ten[] = '';
                                }
                                D("Travelv")->setStatis("qq", $ten);
                        }else{
                                M('Travelv')->where(array('name'=>'qq'))->delete();
                        }
                        unset($tenqq);
                        $this->delSuccess("操作成功！");
                } else {
                        $model = M("Travelv");
                        $where = array('name' => 'qq');
                        $kefu = $model->where($where)->getField("value");
                        $qq = unserialize($kefu);
                        $this->assign('qq', $qq);
                        return $this->fetch();
                }
        }

        /**
         * @呼叫中心
         */
        public function callcenter() {
                if (IS_POST) {
                        $call = $_POST['call'];
                        $tall = array();
                        foreach ($call as $value) {
                                if (!empty($value['tall'])) {
                                        $tall[] = $value;
                                }
                        }
                        D("Travelv")->setStatis("tall", $tall);
                        unset($call);
                        $this->delSuccess("操作成功！");
                } else {
                        $model = M("Travelv");
                        $where = array('name' => 'tall');
                        $tall = $model->where($where)->getField("value");
                        $talls = unserialize($tall);
                        $this->assign('tall', $talls);
                        return $this->fetch();
                }
        }

        /*
         * 上传logo
         */

        public function logo() {
                if (IS_POST) {
                        $logo = I('post.logo');
                        D("Travelv")->setStatis("logo", $logo);
                        return $this->delSuccess('提交成功');
                } else {
                        $logo = M('Travelv')->where(array('name' => 'logo'))->getField('value');
                        $this->assign('logo', $logo);
                        return $this->fetch();
                }
        }

        /*
         * 上传二维码
         */

        public function erweima() {
                if (IS_POST) {
                        $logo = I('post.erweima');
                        D("Travelv")->setStatis("erweima", $logo);
                        return $this->delSuccess('提交成功');
                } else {
                        $logo = M('Travelv')->where(array('name' => 'erweima'))->getField('value');
                        $this->assign('erweima', $logo);
                        return $this->fetch();
                }
        }

        /*
         * 友情链接
         */

        public function linklist() {
                $map = $this->_search("Link");
                if (I('post.address'))
                        $map['address'] = array('like', "%" . I('post.address') . "%");
                if (I('post.name'))
                        $map['name'] = array('like', "%" . I('post.name') . "%");
                $this->_list(D("Link"), $map, 'id', false, true);
                return $this->fetch();
        }

        /*
         * 友情链接添加
         */

        public function linklist_add($id = '') {
                if (IS_POST) {
                        $_POST['zone'] = $_POST['locationtf_id'];
                        if ($id) {
                                $this->_update("Link", false, false);
                        } else {
                                $this->_insert("Link", false, false);
                        }
                } else {
                        if ($id) {
                                $nc = D("Link")->field(true)->find($id);
                                $this->assign('link', $nc);
                        } else {
                                $nc['home'] = 0;
                                $nc['line'] = 0;
                                $this->assign('link', $nc);
                        }
                        return $this->fetch();
                }
        }

        /*
         * 友情链接删除
         */

        public function linklist_del($id = '') {
                $this->_delete("Link", $id);
        }

        /*
         * 合同管理
         */

        public function contract() {
                $map = $this->_search("TravelContract");
                $model = M("TravelContract");
                if (!empty($model)) {
                        $this->_list($model, $map, '', false, false);
                }
                return $this->fetch();
        }

        /*
         * 合同管理删除
         */

        public function contract_del($id = '') {
                $this->_delete("TravelContract", $id);
        }

        /*
         * 合同管理编辑
         */

        public function contract_add($id = '') {
                if (IS_POST) {
                        if ($id) {
                                $this->_update("TravelContract", false, false);
                        } else {
                                $this->_insert("TravelContract", false, false);
                        }
                } else {
                        if ($id) {
                                $nc = M("TravelContract")->field(true)->find($id);
                                $this->assign('contract', $nc);
                        } else {
                                $nc = array();
                                $nc['type'] = '';
                                $this->assign('contract', $nc);
                        }
                        return $this->fetch();
                }
        }

}
